PHP

How to print the method name with the associated class name using magic constant __METHOD__ in PHP | PHP programs

How to print the method name with the associated class name using magic constant __METHOD__ in PHP | PHP programs

How to print the method name with the associated class name using magic constant __METHOD__ in PHP | PHP programs

We will print the name of the method with the associated class name using magic constant __METHOD__, where it was declared. The __METHOD__ constant returns case sensitive method name.

<?php

    class Sample
    {
        public function MyMethod()
        {
            print(__METHOD__."<br>");
        }
    }
    
    $S=new Sample();
    $S->MyMethod();
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community